//
//  TestCell.m
//  POP_User
//
//  Created by Rowling on 2019/10/24.
//  Copyright © 2019 Rowling. All rights reserved.
//

#import "TestCell.h"

@implementation TestCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setModel:(TestNetToolModel *)model {
    _model = model;
    NSString * desStr;
    if (model.headerStr) {
        desStr = [NSString stringWithFormat:@"时间:%@--%@\nHttp请求\n请求地址-->%@\n请求头-->%@\n请求参数:-->\n%@\n返回值:-->%@\n",model.timeStr,model.methodStr,model.urlStr,model.headerStr,model.paramStr,model.responsStr];
    } else {
        desStr = [NSString stringWithFormat:@"时间:%@--%@\n请求地址-->%@\n请求参数:-->\n%@\n返回值:-->%@\n",model.timeStr,model.methodStr,model.urlStr,model.paramStr,model.responsStr];
    }
    
    
    NSString * redStr = [NSString stringWithFormat:@"%@",model.urlStr];
    NSRange range = [desStr rangeOfString:redStr];
    
    NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:desStr];
    
    [attriStr addAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} range:range];
    
    [attriStr addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]} range:NSMakeRange(0, attriStr.length)];
    if (model.headerStr) {
        NSString * header = [NSString stringWithFormat:@"%@",model.headerStr];
        NSRange range = [desStr rangeOfString:header];
        [attriStr addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0 / 255.0 green:208/255.0 blue:99/255.0 alpha:1]} range:range];
    }
    self.contentLabel.attributedText = attriStr;
}

-(void)setSocketModel:(SocketModel *)socketModel {
    _socketModel = socketModel;
    self.contentLabel.text = [NSString stringWithFormat:@"时间:%@\n收到的数据%@",socketModel.timeStr,socketModel.dic];
}

@end
